strftime[flexible calendar time formatter]

Contents|Index|Previous|Next
strftime
[flexible calendar time formatter]

    SYNOPSIS
    #include <time.h>
    size_t strftime(char *s, size_t maxsize,
                         const char *format,
                         const struct tm *timp);

DESCRIPTION
strftime converts a struct tm representation of the time (at timp) into a string, starting at s and occupying no more than maxsize characters.

You control the format of the output using the string at format. *format can contain two kinds of specifications: text to be copied literally into the formatted string, and time conversion specifications.

Time conversion specifications are two-character sequences beginning with % (use %% to include a percent sign in the output). Each defined conversion specification selects a field of calendar time data from *timp, and converts it to a string in one of the following ways.

%a

An abbreviation for the day of the week.

%A

The full name for the day of the week.

%b

An abbreviation for the month name.

%B

The full name of the month.

%c

A string representing the complete date and time, in the form:

                   Mon Apr 01 13:13:13 1992

%d

The day of the month, formatted with two digits.

%H

The hour (on a 24-hour clock), formatted with two digits.

%I

The hour (on a 12-hour clock), formatted with two digits.

%j

The count of days in the year, formatted with three digits (from 001 to 366).

%m

The month number, formatted with two digits.

%M

The minute, formatted with two digits.

%p

Either AM or PM as appropriate.

%S

The second, formatted with two digits.

%U

The week number, formatted with two digits (from 00 to 53; week number 1 is taken as beginning with the first Sunday in a year). See also %W.

%w

A single digit representing the day of the week: Sunday is day 0.

%W

Another version of the week number: like %U, but counting week 1 as beginning with the first Monday in a year.

%x

A string representing the complete date, in a format like the following example:

                   Mon Apr 01 1992

%X

A string representing the full time of day (hours, minutes, and seconds), in a format like the following example:

                   13:13:13

%y

The last two digits of the year.

%Y

The full year, formatted with four digits to include the century.

%Z

Defined by ANSI C as eliciting the time zone, if available; it is not available in this implementation (which accepts %Z but generates no output for it).

%%

A single character, %.

RETURNS
When the formatted time takes up no more than maxsize characters, the result is the length of the formatted string. Otherwise, if the formatting operation was abandoned due to lack of room, the result is 0, and the string starting at s corresponds to just those parts of *format that could be completely filled in within the maxsize limit.

COMPLIANCE
ANSI C requires strftime, although it does not specify the contents of *s when the formatted string would require more than maxsize characters.

strftime requires no supporting OS subroutines.

Top|Contents|Index|Previous|Next